﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TemplateWeb.Models.ViewModels.GroupViewModel>" %>

<script type="text/javascript">
    function submitForm2(ngaydathang) {
        var ngaydathangVal = Date.parse(ngaydathang);
        var ngaygiaohang = document.getElementsByName("Orders_NgayGiaoHang").item(0);
        var ngaygiaohangVal = Date.parse(ngaygiaohang.value);

        if (ngaydathangVal > ngaygiaohangVal) {
            alert("Ngày đặt hàng nhỏ hơn ngày giao hàng");
            return false;
        }

        $('#MySubmitForm').submit();
        // suppress default link action
        return true;
    }
</script>
    
<% using (Html.BeginForm("UpdateOrders", "Admin", FormMethod.Post, new { id = "MySubmitForm" })){ %>
<table class="Grid" cellpadding="0" cellspacing="0">
	<thead>
		<tr>
			<th>ID</th>
            <th>Ngày đặt hàng</th>
			<th>Đã xác nhận</th>
			<th>Đã giao hàng</th>
            <th>Ngày giao hàng</th>
			<th></th>
            <th></th>
		<tr>
	</thead>
	<% for (int i=0; i<Model.DonDatHangModel.GetModel.LstObjModel.Count; i++){
		if (i % 2 != 0) {%>
		<tr class="Row" id="row-<%= Model.DonDatHangModel.GetModel.LstObjModel[i].ID %>">
		<% }
		else { %>
		<tr class="AlternatingRow" id="row-<%= Model.DonDatHangModel.GetModel.LstObjModel[i].ID %>">
		<% } %>
            <td><span style=""><%= Model.DonDatHangModel.GetModel.LstObjModel[i].ID %></span></td>
			<td><span style=""><%= string.Format("{0:dd/MM/yyyy hh:mm:ss}", Model.DonDatHangModel.GetModel.LstObjModel[i].NgayDatHang.Value)%></span></td>
        <% if (Model.DonDatHangModel.GetModel.LstObjModel[i].ID == Model.DonDatHangModel.EditModel.ID)
            { %>
			<td><span style=""><%= Html.CheckBox("IsVerified", Model.DonDatHangModel.GetModel.LstObjModel[i].DaXacNhan.Value )%></span></td>
			<td><span style=""><%= Html.CheckBox("IsShipped", Model.DonDatHangModel.GetModel.LstObjModel[i].DaGiaoHang.Value )%></span></td>
            <td>
                <input type="text" name="Orders_NgayGiaoHang" id="Orders_NgayGiaoHang" value="<%= Model.DonDatHangModel.GetModel.LstObjModel[i].NgayGiaoHang == null ? string.Empty : Model.DonDatHangModel.GetModel.LstObjModel[i].NgayGiaoHang.Value.ToShortDateString() %>" />
            </td>
            <td>
				<a href="#" onclick="submitForm2('<%= Model.DonDatHangModel.GetModel.LstObjModel[i].NgayDatHang.Value %>');">
                    <span style="text-decoration: underline">Update</span>
                </a>
				&nbsp;
                <%= Html.Hidden("Orders_From", Model.DonDatHangModel.ReferKeys.From)%>
                <%= Html.Hidden("Orders_To", Model.DonDatHangModel.ReferKeys.To)%>
				<%= Html.Hidden("Orders_ID", Model.DonDatHangModel.GetModel.LstObjModel[i].ID)%>
                <a href="../../Admin/CancelEditingOrders?idorder=<%= Model.DonDatHangModel.GetModel.LstObjModel[i].ID %>&from=<%= Model.DonDatHangModel.ReferKeys.From.ToString() %>&to=<%= Model.DonDatHangModel.ReferKeys.To.ToString() %>">
					<span style="text-decoration: underline">Cancel</span>
				</a>
			</td>
         <% }
            else
            { %>
            <td><span style=""><%= Html.CheckBox("IsVerified2", Model.DonDatHangModel.GetModel.LstObjModel[i].DaXacNhan.Value, new { disabled = "disabled" })%></span></td>
			<td><span style=""><%= Html.CheckBox("IsShipped2", Model.DonDatHangModel.GetModel.LstObjModel[i].DaGiaoHang.Value, new { disabled = "disabled" })%></span></td>
            <td><span style=""><%= Model.DonDatHangModel.GetModel.LstObjModel[i].NgayGiaoHang == null ? string.Empty : string.Format("{0:dd/MM/yyyy hh:mm:ss}", Model.DonDatHangModel.GetModel.LstObjModel[i].NgayGiaoHang.Value)%></span></td>
            <td>
				<a href="../../Admin/EditOrders?idorder=<%= Model.DonDatHangModel.GetModel.LstObjModel[i].ID %>&from=<%= Model.DonDatHangModel.ReferKeys.From.ToString() %>&to=<%= Model.DonDatHangModel.ReferKeys.To.ToString() %>">
					<span style="color: Blue; text-decoration: underline">Edit</span>
				</a>
			</td>
         <% } %>
            <td style="text-align: center">
                <a href="../../Admin/SelectOrderDetail?idorder=<%= Model.DonDatHangModel.GetModel.LstObjModel[i].ID %>&from=<%= Model.DonDatHangModel.ReferKeys.From.ToString() %>&to=<%= Model.DonDatHangModel.ReferKeys.To.ToString() %>">
					<span style="">Select</span>
				</a>
			</td>
		</tr>
	<% } %>  
</table>
<% if (Model.SelectedDonDatHangModel != null)
   { %>
   <%
       var total = 0.0;
       for (int i = 0; i < Model.ChiTietDonDatHangModel.GetModel.LstObjModel.Count; i++)
       {
           total += (Model.ChiTietDonDatHangModel.GetModel.LstObjModel[i].SoLuong.Value * Model.ChiTietDonDatHangModel.GetModel.LstObjModel[i].Gia.Value);
       }
    %>
    <br /><br />
    <span style="font-size:18px; font-weight:bold;">Order <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].ID %></span>
    <br />
    <table class="AdminPageText">
        <tr>
        <td width="130" style="font-weight: bold;">Tổng tiền:</td>
        <td style="font-weight: bold; color: Red">
            <%= string.Format("{0:0,0}", total)%> Đ
        </td>
        </tr>
        <tr>
        <td width="130">Mã Khách hàng:</td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].ID%>
        </td>
        </tr>
        <tr>
        <td width="130">Tên khách hàng:</td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].NguoiDung.HoTen%>
        </td>
        </tr>
        <tr>
        <td width="130">Tên người nhận:</td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].TenNguoiNhan %>
        </td>
        </tr>
        <tr>
        <td width="130">SĐT người nhận:</td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].SoDienThoaiNguoiNhan %>
        </td>
        </tr>
        <tr>
        <td width="130">Địa chỉ người nhận:</td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].DiaChiNguoiNhan %>
        </td>
        </tr>
        <tr>
        <td width="130">Ngày đặt hàng:</td>
        <td>
            <%= string.Format("{0:dd/MM/yyyy hh:mm:ss}", Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].NgayDatHang.Value)%>
        </td>
        </tr>
        <tr>
        <td width="130">Đã xác nhận:</td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].DaXacNhan.Value ? "Rồi" : "Chưa" %>
        </td>
        </tr>
        <tr>
        <td width="130">Đã giao hàng:</td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].DaGiaoHang.Value ? "Rồi" : "Chưa"%>
        </td>
        </tr>
        <tr>
        <td width="130">Ngày giao hàng:</td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].NgayGiaoHang == null ? string.Empty : string.Format("{0:dd/MM/yyyy hh:mm:ss}", Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].NgayGiaoHang.Value)%>
        </td>
        </tr>
        <tr>
        <td width="130">Chú thích thêm:</td>
        <td>
            <%= Model.SelectedDonDatHangModel.GetModel.LstObjModel[0].ChuThich %>
        </td>
        </tr>
    </table>
    <br />
    <div class="AdminPageText">
    Chi tiết đơn đặt hàng
    </div>
    <table class="Grid" cellpadding="0" cellspacing="0">
	<thead>
		<tr>
			<th style="text-align: center;">STT</th>
            <th style="text-align: left; padding-left: 10px;">Tên sách</th>
            <th style="text-align: center;">Số lượng</th>
			<th style="text-align: center;">Đơn giá</th>
            <th style="text-align: center;">Thành tiền</th>
		<tr>
	</thead>
	<% for (int i=0; i<Model.ChiTietDonDatHangModel.GetModel.LstObjModel.Count; i++){
		if (i % 2 != 0) {%>
		<tr class="Row" id="Tr1">
		<% }
		else { %>
		<tr class="AlternatingRow" id="row-<%= Model.ChiTietDonDatHangModel.GetModel.LstObjModel[i].ID %>">
		<% } %>
             <td style="text-align: center"><span style=""><%= (i + 1) %></span></td>
            <td style="text-align: left; padding-left: 10px;"><span style=""><%= Model.ChiTietDonDatHangModel.GetModel.LstObjModel[i].SanPham.TenSanPham %></span></td>
			<td style="text-align: center"><span style=""><%= Model.ChiTietDonDatHangModel.GetModel.LstObjModel[i].SoLuong.Value %></span></td>
			<td style="text-align: center"><span style=""><%= string.Format("{0:0,0}", Model.ChiTietDonDatHangModel.GetModel.LstObjModel[i].Gia.Value) %> Đ</span></td>
            <td style="text-align: center"><span style=""><%= string.Format("{0:0,0}", Model.ChiTietDonDatHangModel.GetModel.LstObjModel[i].SoLuong.Value * Model.ChiTietDonDatHangModel.GetModel.LstObjModel[i].Gia.Value) %> Đ</span></td>
		</tr>
	<% } %>  
</table>
<% } %>
<% } %>